/**
 * 根据引导设置动态渲染任务模块，用于月评、季评中
 * 注意：转正多个页面有用的该组件，故抽离。根据需求及时优化代码逻辑
 * 参见：http://172.16.6.101:81/cur/Timmy/%E5%85%A5%E8%BD%AC%E8%B0%83%E7%A6%BB%E3%80%90%E8%BD%AC%E6%AD%A3%E7%AE%A1%E7%90%86%E3%80%9120210118/#id=1tvaff&p=%E8%AF%95%E7%94%A8%E6%9C%9F%E8%80%83%E8%AF%84%E8%A7%84%E5%88%99%E4%B8%9A%E5%8A%A1%E9%80%BB%E8%BE%91&g=1
 */
import React from 'react';
import { Collapse } from '@/molecules';
import { Divider } from 'antd';
import AssessTask from './AssessTask';
import AssessResult from './AssessResult';
import { useAssessSetting } from '../../hooks';

const { Panel } = Collapse;
const map = { weekly: 'w', monthly: 'm', quarterly: 'q' };
const assessTaskTypeMap = { weekly: 'week', monthly: 'month', quarterly: 'quarter' };
export default function AssessResultDynamic({ data = {} }) {
    const { period, assessMonthly = [], assessWeekly = [] } = data;
    const assessSetting = useAssessSetting(data);
    const { showTask } = assessSetting[map[period]] || {};

    const renderResult = () => {
        if (assessMonthly.length > 0 && period === 'quarterly') {
            return (
                <Panel header="月评结果" key="1">
                    <AssessResult
                        data={assessMonthly}
                        assessSetting={assessSetting.m}
                        levels={data?.assessAbility?.levels}
                    />
                </Panel>
            );
        }

        if (assessWeekly.length > 0) {
            return (
                <Panel header="周评结果" key="1">
                    <AssessResult
                        data={assessWeekly}
                        assessSetting={assessSetting.w}
                        levels={data?.assessAbility?.levels}
                    />
                </Panel>
            );
        }

        if (!showTask) {
            return null;
        }

        return (
            <Panel header="任务情况" key="1">
                <AssessTask data={data} type={assessTaskTypeMap[period]} />
            </Panel>
        );
    };

    return (
        <>
            <Collapse bordered={false} defaultActiveKey={['1']}>
                {renderResult()}
            </Collapse>
            {showTask && <Divider />}
        </>
    );
}
